//-----------------------------------------------------------------------------
//  File          : key2dll.h
//  Module        : 
//  Description   : Declrartion & Defination for KEYDLL export functions.
//  Author        : Lewis
//  Notes         :
//
//  Date          Who         Action
//  ------------  ----------- -------------------------------------------------
//  16 Sept 2008  Lewis       Port From CREON.
//-----------------------------------------------------------------------------
#ifndef _INC_KEYDLL_H_
#define _INC_KEYDLL_H_
#include "common.h"

//-----------------------------------------------------------------------------
//   Common Defines
//-----------------------------------------------------------------------------
#define KEYDLL_ID          0x7F

// Command ID
enum {
KDLL_KEYRESET        ,
KDLL_KEYSTATUS       ,
KDLL_KEYINJECT       ,
KDLL_KEYENCRYPT      ,
KDLL_KEYDECRYPT      ,
KDLL_KEY3ENCRYPT     ,
KDLL_KEY3DECRYPT     ,
KDLL_KEYGETX98PIN    ,
KDLL_KEYX99MAC       ,
KDLL_KEYCALMAC       ,
KDLL_SETOPMODE       ,
KDLL_GETOPMODE       ,
KDLL_DUKPTRESET      ,
KDLL_DUKPTINJECT     ,
KDLL_DUKPTGETPIN     ,
KDLL_EXTPPADSET      ,
KDLL_INITOPER	     ,
KDLL_GETOPERPSW      ,
KDLL_TRANSOPERPSW    ,
KDLL_ADDOPER         ,
KDLL_DELETEOPER      ,
KDLL_MODIFYOPERPSW   ,
KDLL_UPDATAOPERSTATE ,
KDLL_GETOPERSTATE    ,
KDLL_GEETOPERTYPE    ,
KDLL_DISPALLOP       ,
//tms+ zx 110315
KDLL_CreatTMSFile       ,
KDLL_CheckTMSFile       ,
KDLL_DeleteTMSFile      ,
//tms+ end

KDLL_FUNC_COUNT
};


//-----------------------------------------------------------------------------
//   KEY related
//-----------------------------------------------------------------------------
//Key status, mode
#define KEY_STATUS_LOADED       0x01
#define KEY_STATUS_DECRYPT      0X02
#define KEY_STATUS_MASTER       0x04
#define KEY_STATUS_SINGLE       0x08
#define KEY_STATUS_DOUBLE       0x10
#define KEY_STATUS_TRIPLE       0x18

//KVC mode
#define KVC_EXIST               0x01

// Key usage
#define USE_LEFT                0x40
#define USE_RIGHT               0x80
#define USE_THIRD               0xC0

//Encryption/Decryption mode
#define MODE_ECB                0
#define MODE_CBC                1

//Key Cmd Response code
#define RESP_OK                 0
#define RESP_KEY_CLR            1
#define RESP_KBD_FAILED         1
#define RESP_INVALID_TID        1
#define RESP_OUT_OF_SEQ         1
#define RESP_TMK_NOT_LOAD       1
#define RESP_KVC_ERR            1
#define RESP_WRONG_KEY_FUNC     1
#define RESP_FONT_TBL_FULL      1
#define RESP_LOCATION_ERROR     1
#define RESP_SINGLE_KEY_ONLY    2
#define RESP_EPROM_KEY_FAILED   2
#define RESP_PARITY_ERROR       2
#define RESP_LCD_ERROR          2
#define RESP_KEY_CANCEL         2
#define RESP_LENGTH_ERROR       2
#define RESP_KEY_EXIST          2
#define RESP_TIMEOUT            3
#define RESP_KEY_INDEX_ERROR    4
#define RESP_MODE_ERROR         5
#define RESP_AUTH_ERROR         6
#define RESP_DATA_LEN_ERR       7

// DUKPT Function response code
#define CMD_OK            0
#define KVC_ERR           1
#define CMD_CANCEL        2
#define NOT_INJECTED      3
#define INVALID_HOST      4
#define DUKPT_HALT        5

//oper psw return code
#define PASSWORD_OK       0
#define PASSWORD_CNCL     1
#define PASSWORD_ERR      2
#define OPER_NOEXIST      3
#define OPER_TYPE_ERR     4
#define OPER_LIMIT        5

//extern void KDLL_KeyReset(BYTE aKeyidx);  0 or 0xFF=>All 
#define KDLL_KeyReset(x)  lib_app_call(KEYDLL_ID, KDLL_KEYRESET, x, 0, 0)

//extern void KDLL_KeyStatus(BYTE *aStatusStr);
#define KDLL_KeyStatus(x)  lib_app_call(KEYDLL_ID, KDLL_KEYSTATUS, (DWORD)x, 0, 0)

//extern WORD KDLL_KeyInject(BYTE *aKeyStr);
#define KDLL_KeyInject(x)  (WORD) lib_app_call(KEYDLL_ID, KDLL_KEYINJECT, (DWORD)x, 0, 0)

//extern WORD KDLL_KeyEncrypt(BYTE aKeyidx, BYTE *aDataBuf, WORD aDataLen);
#define KDLL_KeyEncrypt(x, y, z)  (WORD) lib_app_call(KEYDLL_ID, KDLL_KEYENCRYPT, (DWORD)x, (DWORD)y, (WORD)z)

//extern WORD KDLL_KeyDecrypt(BYTE aKeyidx, BYTE *aDataBuf, WORD aDataLen);
#define KDLL_KeyDecrypt(x, y, z)  (WORD) lib_app_call(KEYDLL_ID, KDLL_KEYDECRYPT, (DWORD)x, (DWORD)y, (WORD)z)

//extern WORD KDLL_Key3Encrypt(BYTE aKeyidx, BYTE *aDataBuf, WORD aDataLen);
#define KDLL_Key3Encrypt(x, y, z)  (WORD) lib_app_call(KEYDLL_ID, KDLL_KEY3ENCRYPT, (DWORD)x, (DWORD)y, (WORD)z)

//extern WORD KDLL_Key3Decrypt(BYTE aKeyidx, BYTE *aDataBuf, WORD aDataLen);
#define KDLL_Key3Decrypt(x, y, z)  (WORD) lib_app_call(KEYDLL_ID, KDLL_KEY3DECRYPT, (DWORD)x, (DWORD)y, (WORD)z)

//extern WORD KDLL_GetX98PIN(BYTE *aPINBlock, BYTE *aPromptMsg, BYTE aKeyidx);
#define KDLL_GetX98PIN(x, y, z)  (WORD) lib_app_call(KEYDLL_ID, KDLL_KEYGETX98PIN, (DWORD)x, (DWORD)y, (DWORD)z)

// extern WORD KDLL_X99CalMAC(BYTE *aMacPtr, BYTE *aDataPtr, DWORD aLen);
#define KDLL_X99CalMAC(x, y, z)  (WORD) lib_app_call(KEYDLL_ID, KDLL_KEYX99MAC, (DWORD)x, (DWORD)y, (DWORD)z)

// extern WORD KeyCalMac(BYTE aKeyIdx, BYTE *aDataBuf, WORD aDataLen)
#define KDLL_KeyCalMac(x, y, z)  (WORD)lib_app_call(KEYDLL_ID, KDLL_KEYCALMAC, (DWORD)x, (DWORD)y, (DWORD)z)

//extern void SetOpMode(BYTE aMode, BYTE *aInitData);
#define KDLL_SetOpMode(x, y)     lib_app_call(KEYDLL_ID, KDLL_SETOPMODE, (DWORD)x, (DWORD)y, (DWORD)0)

//extern void GetOpMode(BYTE *aMode);
#define KDLL_GetOpMode(x)        lib_app_call(KEYDLL_ID, KDLL_GETOPMODE, (DWORD)x, (DWORD)0, (DWORD)0)

//extern BOOLEAN DukptKeyReset(BYTE aKeyIdx);
#define KDLL_DukptKeyReset(x)      (BOOLEAN) lib_app_call(KEYDLL_ID, KDLL_DUKPTRESET, (DWORD)x, (DWORD)0, (DWORD)0)

//extern WORD DukptKeyInject(BYTE *aKeyStr);
#define KDLL_DukptKeyInject(x)     (WORD) lib_app_call(KEYDLL_ID, KDLL_DUKPTINJECT, (DWORD)x, (DWORD)0, (DWORD)0)

//extern WORD DukptGetPin(BYTE *aPINBlock, BYTE *aPromptMsg, BYTE aKeyIdx);
#define KDLL_DukptGetPin(x, y, z)  (WORD) lib_app_call(KEYDLL_ID, KDLL_DUKPTGETPIN, (DWORD)x, (DWORD)y, (DWORD)z)

//extern void ExtPPadSetup(DWORD aExtAid, DWORD aExtFuncId);
#define KDLL_ExtPPadSetup(x, y)    lib_app_call(KEYDLL_ID, KDLL_EXTPPADSET, (DWORD)x, (DWORD)y, (DWORD)0)

//extern void KDLL_InitOper(void)
#define KDLL_InitOper()        lib_app_call(KEYDLL_ID, KDLL_INITOPER, (DWORD)0, (DWORD)0, (DWORD)0)

//extern DWORD GetOperPsw(WORD iOperNo,WORD iOperType)
#define KDLL_GetOperPsw(x, y)      lib_app_call(KEYDLL_ID, KDLL_GETOPERPSW, (DWORD)x, (DWORD)y, (DWORD)0)

//extern DWORD TransOperPsw(WORD iOperNo, WORD iOperType, BYTE *sbOperPwd)
#define KDLL_TransOperPsw(x, y, z)  lib_app_call(KEYDLL_ID, KDLL_TRANSOPERPSW, (DWORD)x, (DWORD)y, (DWORD)z)

//extern DWORD AddOper(WORD iOperNo,WORD iOperType,WORD iOwnType);
#define KDLL_AddOper(x, y, z)      lib_app_call(KEYDLL_ID,KDLL_ADDOPER,(DWORD)x,(DWORD)y,(DWORD)z)

//extern DWORD DeleteOper(WORD iOperNo,WORD iOwnOperNo);
#define KDLL_DeleteOper(x, y)      lib_app_call(KEYDLL_ID,KDLL_DELETEOPER,(DWORD)x,(DWORD)y,(DWORD)0)

//extern DWORD ModifyOperPsw(WORD iOperNo);
#define KDLL_ModifyOperPsw(x)      lib_app_call(KEYDLL_ID,KDLL_MODIFYOPERPSW,(DWORD)x,(DWORD)0,(DWORD)0)

//extern DWORD UpdataOperState(WORD iOperNo,WORD iState);
#define KDLL_UpdataOperState(x, y) lib_app_call(KEYDLL_ID,KDLL_UPDATAOPERSTATE,(DWORD)x,(DWORD)y,(DWORD)0)

//extern DWORD GetOperState(WORD iOperNo);
#define KDLL_GetOperState(x)       lib_app_call(KEYDLL_ID,KDLL_GETOPERSTATE,(DWORD)x,(DWORD)0,(DWORD)0)

//extern DWORD GetOperType(WORD iOperNo);
#define KDLL_GetOperType(x)        lib_app_call(KEYDLL_ID,KDLL_GEETOPERTYPE,(DWORD)x,(DWORD)0,(DWORD)0)

//extern DWORD DispAllOp(void);
#define KDLL_DispAllOp()           lib_app_call(KEYDLL_ID,KDLL_DISPALLOP,(DWORD)0,(DWORD)0,(DWORD)0)

//tms+ zx 110315
//BOOLEAN CreatTMSFile(void)
#define KDLL_CreatTMSFile()             lib_app_call(KEYDLL_ID, KDLL_CreatTMSFile, (DWORD)0, (DWORD)0, (DWORD)0)
//BOOLEAN CheckTMSFile(void)
#define KDLL_CheckTMSFile()             lib_app_call(KEYDLL_ID, KDLL_CheckTMSFile, (DWORD)0, (DWORD)0, (DWORD)0)
//BOOLEAN DeleteTMSFile(void)
#define KDLL_DeleteTMSFile()             lib_app_call(KEYDLL_ID, KDLL_DeleteTMSFile, (DWORD)0, (DWORD)0, (DWORD)0)
//tms+ end

#endif // _INC_KEYDLL_H_
